<template>
  <el-dialog v-model="dialog" title="选择项目" style="width: 400px" :close-on-click-modal="false"
        :close-on-press-escape="false">
    <div style="text-align: center">
      <el-form :model="form" ref="ruleFormRef" :rules="rules">
        <el-form-item label="项目名称">
          <el-select
            v-model="form.projectId"
            filterable
            clearable
            placeholder="请选择公司名称"
          >
            <el-option
              v-for="item in options"
              :key="item.enterpriseId"
              :label="item.cmpName"
              :value="item.enterpriseId"
            />
            <template #prefix>
              <el-icon class="el-input__icon"><search /></el-icon>
            </template>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
       <!--  <el-button @click="resetForm(ruleFormRef)">取消</el-button> -->
        <el-button type="primary" @click="submitForm(ruleFormRef)">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { defineProps, watch, onBeforeMount, ref, reactive } from "vue";
import mitts from "@/utils/bus.js";
import { getNameList } from "@/api/enterprise";
import { ElMessage } from "element-plus";
const prop = defineProps({
  dialogTableVisible: Boolean,
});
const options = ref([]);
const ruleFormRef = ref();
const dialog = ref(false);
const form = reactive({
  projectId: "",
});
const rules = reactive({
  projectId: [
    {
      required: true,
      message: "请选择一个项目",
      trigger: "change",
    },
  ],
});
watch(prop.dialogTableVisible, (newValue, oldValue) => {
  console.log(prop.dialog);
});
onBeforeMount(() => {
  mitts.on("show", (e) => {
    console.log(e);
    dialog.value = true;
  });
});
const doDataList = () => {
  getNameList()
    .then((res) => {
      options.value = res.data;
    })
    .catch((msg) => {});
};

/**
 * 确定按钮
 */
const submitForm = (FormInstance) => {
  if (form.projectId != "" && form.projectId != undefined) {
    mitts.emit("projectId", form.projectId);
    dialog.value = false;
  }else{
    ElMessage.error("请选择一个企业！")
  }

};
/**
 * 取消按钮
 */
const resetForm = (FormInstance) => {
  dialog.value = false;
};

doDataList();
</script>

<style lang="less" scoped>
.text-lab {
  margin-right: 5px;
}
.dialog-footer {
  text-align: center;
}
</style>
